/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */
import {PERSON_DETAILS, PERSON_OPERA, STUDENT_PROPERTY, STUDENT_SEX} from '@/const/personDict'
import {rule} from "@/util/rule";

export const tableOption = {
    border: true,
    index: true,
    indexLabel: '序号',
    stripe: true,
    menuAlign: 'center',
    menuWidth: 190,
    menuType: 'button',
    align: 'center',
    refreshBtn: true,
    showClomnuBtn: false,
    searchSize: 'mini',
    searchMenuSpan: 4,
    searchSpan: 4,
    addBtn: false,
    editBtn: false,
    viewBtn: false,
    delBtn:false,
    selection: true,
    reserveSelection: true,
    props: {
        label: 'label',
        value: 'value'
    },
    column: [{
        label: '人员id',
        prop: 'id',
        hide: true,
        viewDisplay: false,
        editDisplay: false,
    }, {
        label: '姓名',
        prop: 'personName',
        type: 'input',
        search: true,
    }, {
        label: '学号',
        prop: 'number',
        dicData: PERSON_DETAILS,
    }, {
        label: '性别',
        prop: 'sex',
        search: true,
        type: 'select',
        dicData: STUDENT_SEX,
    }, {
        label: '年级',
        prop: 'parentName',
        type: 'select',
        dicData: PERSON_DETAILS,
        editDisplay: false,
    }, {
        label: '班级',
        prop: 'deptName',
        type: 'select',
        dicData: PERSON_DETAILS,
        editDisplay: false,
    }, {
        label: '学生属性',
        prop: 'identityKey',
        search: true,
        type: 'select',
        dicUrl: '/campus/identity/selectAll?groupNum=2',
        dicMethod: 'get',
        props: {
            label: 'name',
            value: 'id'
        },
    }, {
        label: '楼栋',
        prop: 'buildingName',
        dicData: PERSON_DETAILS,
    }, {
        label: '楼栋',
        prop: 'buildingId',
        hide: true,
        search: true,
        type: 'select',
        dicUrl: '/campus/building/selectAll',
        dicMethod: 'get',
        props: {
            label: 'buildingName',
            value: 'buildingId'
        }
    },
        {
            label: '宿舍号',
            prop: 'dormNumber',
            dicData: PERSON_DETAILS,
            search: true,
            type: 'input',
        }, {
            label: '手机号',
            prop: 'phone',
            hide: true,
            viewDisplay: true,
        }, {
            width: 100,
            label: '人脸照片',
            prop: 'photoId',
            // slot: true,
            type: 'upload',
            listType: 'picture-img',
            propsHttp: {
                home: '/campus/persons/photo/'
            },
        },
        {
            width: 120,
            label: '可通行门禁',
            prop: 'grouplist',
            slot: true,
        }, {
            width: 130,
            label: '通行方案',
            prop: 'schemeName',
            type: 'select',
            dicData: PERSON_DETAILS
    }, {
        width: 120,
        label: '人员修改时间',
        prop: 'updateTime',
        type: 'datetime',
        format: 'yyyy-MM-dd HH:mm',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        editDisplay: false,
    }, {
        width: 100,
        label: '修改操作人',
        prop: 'operator',
        editDisplay: false,
        dicData: PERSON_OPERA
    }, {
        label: '状态',
        prop: 'property',
        search: true,
        slot: true,
        type: 'select',
        addDisplay: false,
        dicData: STUDENT_PROPERTY
    },
        // {
        //     label: '年级/班级',
        //     prop: 'deptId',
        //     search: true,
        //     filter: false,
        //     type: 'tree',
        //     hide: true,
        //     dicUrl: '/campus/sysdept/detpTree/1/2,3',
        //     dicMethod: 'get',
        //     props: {
        //         label: 'name',
        //         value: 'deptId'
        //     },
        // },
    ]
}


export const addOption = {

    submitBtn: false,
    emptyBtn: false,
    // props: {
    //     label: 'label',
    //     value: 'value'
    // },
    column: [
        {
            label: '姓名',
            prop: 'personName',
            type: 'input',
            rules: [{
                validator: rule.chineselanguage,
                required: true,
                trigger: 'change'
            }]
        }, {
            label: '学号',
            prop: 'number',
            rules: [{
                validator: rule.number,
                trigger: 'change'
            }],
            placeholder: '学号若为空，则自动生成',
        },
        {
            label: '年级',
            prop: 'dept',
            type: 'select',
            clearable: false,
            defaultExpandAll: true,
            dicUrl: '/admin/dept/PermissionTree',
            cascaderItem: ['deptName'],
            dicFormatter: (res) => {
                let gradeArr = res.data
                let value = []
                if(gradeArr.length> 0){
                    for(let i of gradeArr){
                        if(i.typeNum == "2" && i.isLock === false){
                            value.push(i)
                        }
                    }
                    console.log(value)
                    return value
                }
            },
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'id'
            },
            rules: [{
                required: true,
                trigger: 'none'
            }]
        },
        {
            label: '班级',
            prop: 'deptName',
            filter: false,
            type: 'select',
            clearable: false,
            defaultExpandAll: true,
            dicUrl: '/campus/sysdept/detpTree/{{key}}/1,2,3',
            dicFormatter: (res) => {
                // console.log(res.data[0].children)
                return res.data[0].children;//返回字典的层级结构
            },
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'deptId',
            },
            rules: [{
                required: true,
                trigger: 'none'
            }]
        },

        // {
        //     label: '年级/班级',
        //     prop: 'deptId',
        //     type: 'tree',
        //     clearable: false,
        //     hide: true,
        //     dicUrl: '/campus/sysdept/detpTree/1/2,3',
        //     dicMethod: 'get',
        //     props: {
        //         label: 'name',
        //         value: 'deptId'
        //     },
        //     rules: [{
        //         required: true,
        //         trigger: 'none'
        //     }]
        // },
        {
            label: '学生属性',
            prop: 'identityKey',
            type: 'select',
            clearable: false,
            dicUrl: '/campus/identity/selectAll?groupNum=2',
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'id'
            },
            rules: [{
                required: true,
                trigger: 'none'
            }],
            change(val) {
                var buildingId = this.findObject(addOption.column, 'buildingId')
                var hidedorm = this.findObject(addOption.column, "dormNumber")
                if (val.value === 40) {
                    buildingId.display = false
                    hidedorm.display = false
                } else {
                    buildingId.display = true
                    hidedorm.display = true
                }
            },
        },
        {
            label: '身份证号',
            prop: 'identityId',
            display: true,
            rules: [{
                required: true,
                trigger: 'none'
            }]
        },{
            label: '性别',
            prop: 'sex',
            type: 'select',
            clearable: false,
            dicData: STUDENT_SEX,
            rules: [{
                required: true,
                trigger: 'none'
            }]
        },
        // {
        //     label: '通行方案',
        //     prop: 'schemeId',
        //     type: 'select',
        //     clearable: false,
        //     dicUrl: '/campus/scheme/selectAll',
        //     dicMethod: 'get',
        //     props: {
        //         label: 'schemeName',
        //         value: 'id'
        //     },
        //     rules: [{
        //         required: true,
        //         trigger: 'none'
        //     }]
        // },
        {
            label: '楼栋',
            prop: 'buildingId',
            type: 'select',
            clearable: false,
            display: true,
            dicUrl: '/campus/building/selectAll',
            dicMethod: 'get',
            props: {
                label: 'buildingName',
                value: 'buildingId'
            },
            rules: [{
                required: true,
                trigger: 'none'
            }]
        }, {
            label: '宿舍号',
            prop: 'dormNumber',
            display: true,
            rules: [{
                required: true,
                trigger: 'none'
            }]
        },
        {
            label: '手机号',
            prop: 'phone',
            rules: [{
                validator: rule.phone,
                required: true,
                trigger: 'blur'
            }]
        },
        // {
        //     label: '可通行门禁',
        //     prop: 'accessControlIds',
        //     type: 'select',
        //     clearable: false,
        //     dataType: 'array',
        //     multiple: true,
        //     dicUrl: '/campus/accesscontrolgroup/selectAll',
        //     dicMethod: 'get',
        //     dicFlag: true,
        //     props: {
        //         label: 'groupName',
        //         value: 'id'
        //     }
        // },
    ],
}
export const editOption = {
    submitBtn: false,
    emptyBtn: false,
    // props: {
    //     label: 'label',
    //     value: 'value'
    // },
    column: [
        {
            label: '姓名',
            prop: 'personName',
            type: 'input',
            rules: [{
                validator: rule.chineselanguage,
                trigger: 'change'
            }]
        }, {
            label: '学号',
            prop: 'number',
            rules: [{
                validator: rule.number,
                trigger: 'change'
            }]
        },

        {
            label: '年级',
            prop: 'pid',
            type: 'select',
            filter: false,
            clearable: false,
            defaultExpandAll: true,
            cascaderItem: ['deptId'],
            dicUrl: '/admin/dept/PermissionTree',
            dicFormatter: (res) => {
                let gradeArr = res.data
                let value = []
                if(gradeArr.length> 0){
                    for(let i of gradeArr){
                        if(i.typeNum == "2" && i.isLock === false){
                            value.push(i)
                        }
                    }
                    console.log(value)
                    return value
                }
            },
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'id'
            },
        },
        {
            label: '班级',
            prop: 'deptId',
            filter: false,
            type: 'select',
            clearable: false,
            defaultExpandAll: true,
            dicUrl: '/campus/sysdept/detpTree/{{key}}/1,2,3',
            dicFormatter: (res) => {
                return res.data[0].children;//返回字典的层级结构
            },
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'deptId',
            },
        },


        //     {
        //     label: '年级/班级',
        //     prop: 'deptId',
        //     type: 'tree',
        //     clearable: false,
        //     hide: true,
        //     dicUrl: '/campus/sysdept/detpTree/1/2,3',
        //     dicMethod: 'get',
        //     props: {
        //         label: 'name',
        //         value: 'deptId'
        //     }
        // },
        {
            label: '学生属性',
            prop: 'identityKey',
            type: 'select',
            clearable: false,
            dicUrl: '/campus/identity/selectAll?groupNum=2',
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'id'
            },
            change(val) {
                var buildingId = this.findObject(editOption.column, 'buildingId')
                var hidedorm = this.findObject(editOption.column, "dormNumber")
                if (val.value === 40) {
                    buildingId.display = false
                    hidedorm.display = false
                } else {
                    buildingId.display = true
                    hidedorm.display = true
                }
            },
        }, {
            label: '身份证号',
            prop: 'identityId1',
            display: true,
            rules: [{
                required: true,
                trigger: 'none'
            }]
        },{
            label: '性别',
            prop: 'sex',
            type: 'select',
            clearable: false,
            dicData: STUDENT_SEX,
        },
        // {
        //     label: '通行方案',
        //     prop: 'schemeId',
        //     type: 'select',
        //     clearable: false,
        //     dicUrl: '/campus/scheme/selectAll',
        //     dicMethod: 'get',
        //     props: {
        //         label: 'schemeName',
        //         value: 'id'
        //     },
        // },
        {
            label: '楼栋',
            prop: 'buildingId',
            type: 'select',
            clearable: false,
            display: true,
            dicUrl: '/campus/building/selectAll',
            dicMethod: 'get',
            props: {
                label: 'buildingName',
                value: 'buildingId'
            }
        }, {
            label: '宿舍号',
            prop: 'dormNumber',
            display: true,
            rules: [{
                required: true,
                trigger: 'none'
            }]
        },
        {
            label: '手机号',
            prop: 'phone',
            rules: [{
                validator: rule.phone,
                trigger: 'blur'
            }]
        },
        // {
        //     label: '可通行门禁',
        //     prop: 'accessControlIds',
        //     type: 'select',
        //     clearable: false,
        //     dataType: 'array',
        //     multiple: true,
        //     dicUrl: '/campus/accesscontrolgroup/selectAll',
        //     dicMethod: 'get',
        //     dicFlag: true,
        //     props: {
        //         label: 'groupName',
        //         value: 'id'
        //     }
        // },

    ],
}
